package com.inno.system.controller;

import com.inno.system.entity.PlannerBanner;
import com.inno.system.enums.TypeEnum;
import com.inno.system.resp.CommonReturnType;
import com.inno.system.service.PlannerBannerService;
import jakarta.annotation.Resource;
import lombok.Getter;
import lombok.Setter;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * (PlannerBanner)表控制层
 *
 * @author makejava
 * @since 2025-01-04 17:17:33
 */
@RestController
@RequestMapping("/system/banner")
public class PlannerBannerController {
    /**
     * 服务对象
     */
    @Resource
    private PlannerBannerService plannerBannerService;


    /**
     * list
     */
    @GetMapping("/list")
    public ResponseEntity<?> list(){
        List<PlannerBanner> list = this.plannerBannerService.list();
        for (PlannerBanner plannerBanner : list) {
            plannerBanner.setTypeDesc(plannerBanner.getType());
        }
        return ResponseEntity.ok(list);
    }

    @GetMapping("/mp-list")
    public CommonReturnType<List<PlannerBanner>> queryList(){
        return CommonReturnType.success(this.plannerBannerService.list());
    }
    /**
     * type list
     */
    @GetMapping("/typeList")
    public ResponseEntity<?> typeList(){
        return ResponseEntity.ok(Arrays.stream(TypeEnum.values()).map(typeEnum -> {
            TypeVO typeVO = new TypeVO();
            typeVO.setCode(typeEnum.getCode());
            typeVO.setDesc(typeEnum.getDesc());
            return typeVO;
        }).toList());
    }
    @Getter
    @Setter
    public static class TypeVO{
        private String code;
        private String desc;
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<PlannerBanner> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.plannerBannerService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param plannerBanner 实体
     * @return 新增结果
     */
    @PutMapping("/create")
    public ResponseEntity<PlannerBanner> add(@RequestBody PlannerBanner plannerBanner) {
        return ResponseEntity.ok(this.plannerBannerService.insert(plannerBanner));
    }

    /**
     * 编辑数据
     *
     * @param plannerBanner 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public ResponseEntity<PlannerBanner> edit(@RequestBody PlannerBanner plannerBanner) {
        return ResponseEntity.ok(this.plannerBannerService.update(plannerBanner));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Long id) {
        return ResponseEntity.ok(this.plannerBannerService.deleteById(id));
    }

}

